package com.tensai.other;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @author Tensai
 */
@Slf4j
public class TimerTest {

    @Test
    public void test(){
        log.info("About to schedule task.");
        new Reminder(3);
        log.info("Task scheduled.");
    }

    public static class Reminder{
        Timer timer;
        public Reminder(int sec){
            timer = new Timer();
            timer.schedule(new TimerTask(){
                public void run(){
                    log.info("Time's up!");
                    timer.cancel();
                }
            }, sec*1000L);
        }
    }

    public static void main(String[] args) {
        log.info("About to schedule task.");
        new Reminder(3);
        log.info("Task scheduled.");
    }
}